package com.example.aigc_education.integration.processor.v1.sync;

import com.example.aigc_education.enums.LanguageType;
import com.example.aigc_education.enums.PlanTargetType;
import com.example.aigc_education.enums.PlanStageType;
import com.example.aigc_education.integration.emuns.CozeWorkflowTypeV2;
import com.example.aigc_education.integration.processor.v1.CozeSyncWFProcessor;
import com.example.aigc_education.integration.request.CozeRequest;
import com.example.aigc_education.integration.request.params.v1.CozeStudyPlanParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CozeStudyPlanSyncWFProcessor extends CozeSyncWFProcessor<CozeStudyPlanParam> {


    @Override
    protected String workflowId() {
        return CozeWorkflowTypeV2.STUDY_PLAN.getWorkflowId();
    }


    @Override
    protected boolean isParamValid(CozeRequest<CozeStudyPlanParam> request) {
        //参数校验
        CozeStudyPlanParam parameters = request.getParameters();
        if (parameters == null) {
            log.error("参数为空");
            return false;
        }
        // 校验 topic
        if (parameters.getSubject() == null || parameters.getSubject().trim().isEmpty()) {
            log.error("主题不能为空");
            return false;
        }

        // 校验 grade
        try {
            PlanStageType.fromTitle(parameters.getGrade());
        } catch (IllegalArgumentException e) {
            log.error("年级无效", e);
            return false;
        }

        // 校验 goal
        try {
            PlanTargetType.fromTitle(parameters.getGoal());
        } catch (IllegalArgumentException e) {
            log.error("希望水平无效", e);
            return false;
        }

        // 校验 language
        try {
            LanguageType.fromTitle(parameters.getLanguage());
        } catch (IllegalArgumentException e) {
            log.error("语言无效", e);
            return false;
        }
        return true;
    }
}
